package com.xbs.controller.user;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.entity.UserEntity;
import com.xbs.service.user.MessageService;
@WebServlet("/userview/myCenter/payment")
public class MyCenter_payment extends BaseServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String uname = (String) req.getSession().getAttribute("uname");
		MessageService messageservice = new MessageService();
		UserEntity message = messageservice.selAll(uname);
		req.setAttribute("message", message);
		//生成随机四位验证码
		int num = (int) Math.floor(Math.random()*9000+1000);
		//清除当前会话
		req.getSession().invalidate();
		//生成验证码
		req.setAttribute("yzm", num);
		//转发到jsp页面
		forward("/userview/myCenter/myCenter_payment");
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String uname = (String) req.getSession().getAttribute("uname");
		String passwords = req.getParameter("passwords");
		String passwordAgains = req.getParameter("passwordAgains");
		MessageService messageservice = new MessageService();
		UserEntity str1 = messageservice.selAll(uname);
		String telphone = str1.getUser_telphone();
		req.setAttribute("message", str1);
		if(passwords == null || passwords.equals("")){
			String str2 = "请输入支付密码！";
			req.setAttribute("password1", str2);
		}else if(passwordAgains == null || passwordAgains.equals("")){
			String str3 = "请确认支付密码！";
			req.setAttribute("password2", str3);
		}else if(passwords.equals(passwordAgains)){
			messageservice.updatePay(passwords, telphone);
			String str4 = "修改成功！";
			req.setAttribute("password3", str4);
		}else{
			String str5 = "两次输入的密码不一样！";
			req.setAttribute("password4", str5);
		}
		forward("/userview/myCenter/myCenter_payment");
	}
}
